package com.cvc.tracker.es;

public class Capturer implements Runnable {
	
	private volatile boolean pleaseStop;

	public void tellMeToStop() {
		pleaseStop = true;
	}
	void grabImage() {
		synchronized (this) {
			CVCTLib.grab();
		}
	}

	void getImageToRender() {
		synchronized (this) {
			CVCTLib.copyToRender();
		}
	}

	void getImageToIM() {
		synchronized (this) {
			CVCTLib.copyToIMProcessing();
		}
	}

	@Override
	public void run() {
		pleaseStop = false;
		if(CVCTLib.initCam() == 1)
			System.out.println("INICIOU Camera corretamente " );
		else
			System.out.println("NAO NAO INICIOU Camera corretamente ");
		try {
			while (!pleaseStop) {
				grabImage();
				System.out.println(this.getClass().getName());

				Thread.sleep(10);
			}
		} catch (InterruptedException e) {
			System.out.println("ACABOU " + this.getClass().getName());
		}
		CVCTLib.releaseCam();

	}
}
